package day10;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

class Sell implements Runnable{

    private Integer num;

    public Sell(Integer num) {
        this.num = num;
    }

    @Override
    public void run() {
        System.out.println(num + "累加后的值为:" + sum());
    }

    public int sum(){
        int sum = 0;
        for(int i = 1;i < num + 1;i++) {
            sum += i;
        }
        return sum;
    }

}

public class SellTicketDemo {
    public static void main(String[] args) {
        //创建线程池  线程数量是否越大越好？   除非是有计划的事件,奥运，或春节，618，这个时候把线程数量创建大一些，有个缺点，创建大量线程要更多的时间
        //创建的线程数量过小，会等待
        ExecutorService service = Executors.newFixedThreadPool(3);

        //创建线程对象
        Sell s = new Sell(100);
        Sell s2 = new Sell(200);

        //提交任务给线程池
        service.submit(s);
        service.submit(s2);

        //关闭线程池 正常关闭
        service.shutdown();

        //状态
        System.out.println("是否关闭:" + service.isShutdown());
        System.out.println("是否死亡:" + service.isTerminated());

    }
}
